package dao;

import pojo.Grade;
import utils.DbUtils;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GradeDaoImpl extends DbUtils implements GradeDao {
    @Override
    public List<Grade> selectALl() {
        String sql = "select * from grade";
        List<Grade> list = new ArrayList<>();
        ResultSet query = query(sql, null);
        try {
            while (query.next()){
                Grade grade = new Grade();
                grade.setGradeId(query.getInt("gradeid"));
                grade.setGradeName(query.getString("gradename"));
                list.add(grade);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            closeAll();
        }
        return list;
    }
}
